import axios from 'axios'; 
import { UserAgent } from '../../config/variable';

export const getUserInfo = (token, params) => {
  return axios.get('https://lotswap.dpm.org.cn/lotsapi/up/api/user/info', {
    params,
    headers: {
      'Content-Type': 'application/json',
      'access-token': `${token}`,
      'User-Agent': UserAgent
    }
  });
};

export const getUsereExtInfo = (token, params) => {
  return axios.get('https://lotswap.dpm.org.cn/lotsapi/leaguer/api/userLeaguer/manage/leaguerInfo', {
    params,
    headers: {
      'Content-Type': 'application/json',
      'access-token': `${token}`,
      'User-Agent': UserAgent
    }
  });
};

let lastTime = Date.now();
let lastCanBuyDaysPromise;

export const getCanBuyDays = () => {
  if (lastCanBuyDaysPromise) {
    // 缓存1分钟
    if (Date.now() < lastTime + 1000 * 60 * 1) {
      return lastCanBuyDaysPromise;
    }
  }
  lastTime = Date.now();
  lastCanBuyDaysPromise = axios.get('https://lotswap.dpm.org.cn/dubboApi/product-core/ruleRpcService/canBuyDays', {
    headers: {
      'Content-Type': 'application/json',
      'User-Agent': UserAgent
    }
  });

  return lastCanBuyDaysPromise;
};

export const getCalendartickt = (params) => {
  return axios.get('https://lotswap.dpm.org.cn/lotsapi/merchant/api/fsyy/calendar', {
    params,
    headers: {
      'Content-Type': 'application/json',
      'User-Agent': UserAgent
    }
  });
};

export const merchantParkTicketGridNew = (params) => {
  return axios.get('https://lotswap.dpm.org.cn/lotsapi/merchant/api/merchantParkTicketGridNew', {
    params,
    headers: {
      'Content-Type': 'application/json',
      'User-Agent': UserAgent
    }
  });
};

// export const batchTimeReserveList = (params) => {
//   return axios.get('https://lotswap.dpm.org.cn/lotsapi/order/api/batchTimeReserveList', {
//     params,
//     headers: {
//       'Content-Type': 'application/json',
//       'User-Agent': UserAgent
//     }
//   });
// };

export const ticketVerificationCheck = (token, data) => {
  // const mpDeviceToken = 'v2:wqkBKcU0pguFf1EIqUPSOitzZfWf9rrMVxFnwDh7tMT2ie9PjiQuXoZCFkF+vZOTCXp4AurMQIDP1NFPEQ6hrOqu029WRGjyTpsJWqmnz2nhVTem3Rs1u5MEkHv3Wcszs1aXeSmTaVtyZSUiMl3UcHmnI6VvkgrS6pByrk60wQiSiG/9YK7aIGyLAxPjnRXnW3Vz9cyl1w1aUvxGhnkrrLez+w==';
  return axios.post('https://lotswap.dpm.org.cn/dubboApi/trade-core/tradeCreateService/ticketVerificationCheck', data, {
    headers: {
      Host: "lotswap.dpm.org.cn",
      'Content-Type': 'application/json',
      'access-token': `${token}`,
      'User-Agent': UserAgent,
      // mpOpenId: openId,
      // mpDeviceToken,
      // Referer: 'https://servicewechat.com/wx13169e68a3e63e55/131/page-frame.html',
      // app: 'app_qqmap_tickets',
      // ts: 1709008281
    }
  });
};

export const createOrder = (token, params, data, openId, mpDeviceToken) => {
  return axios.post('https://lotswap.dpm.org.cn/dubboApi/trade-core/tradeCreateService/create?' + params, data, {
    headers: {
      'Content-Type': 'application/json',
      'access-token': `${token}`,
      'User-Agent': UserAgent,
      mpOpenId: openId,
      mpDeviceToken: mpDeviceToken
    }
  });
};

export const login = (data) => {
  return axios.post('https://lotswap.dpm.org.cn/lotsapi/up/api/login', data, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'User-Agent': UserAgent,
    }
  });
};


// curl -X GET "https://lotswap.dpm.org.cn/lotsapi/order/orderPay/toPay?channelProductCode=10809&payOrderNo=20240301930001173107&payType=2003&paySum=40&openId=oOya25CysrTrkEktia4WxypLHn9Y&extendParamJson=%7B%22openId%22%3A%22oOya25CysrTrkEktia4WxypLHn9Y%22%2C%22channelProductCode%22%3A%2210809%22%7D&accountId=2655&userType=C" -H "Host: lotswap.dpm.org.cn" -H "Connection: keep-alive" -H "app: app_qqmap_tickets" -H "ts: 1709306328" -H "mpOpenId: oOya25CysrTrkEktia4WxypLHn9Y" -H "content-type: application/json" -H "access-token: eyJhbGciOiJIUzUxMiJ9.eyJ1IjoiNTMwNTAxMTc5ODQ3NzkwNTkyIiwidCI6IjAiLCJleHAiOjE3MDkzMTE5MTN9.s5GHtFS9YQwfMcM-LXKrD5pNP_UKHoDgeqUoYqfArLSljPi3ENEL022aKxpgbPl6shOkdMpBTE2_3TSKg8O8ow" -H "mpDeviceToken: v2:wqkBZl3U/983UQwGgx1mh9ku+A7ebDZHLJCW2eDOpDBzEyO4uiH/IdTd8NcUU3CMLPQcZQ/20CjX6PzZArxfRT7lvA8corX1lBNoK+Ewu8hy0xdmo1JNZ+6ns2Uc0NZk8RVgrXEuYMCM1qcnB+VSaZ4vChcy+ZBcFBFnatwvRJ12WvIrJoj2nh6eykIfKZL2F7ABQmyznwOtcQA6aw8+J9yLyw==" -H "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.47(0x18002f2a) NetType/WIFI Language/zh_CN" -H "Referer: https://servicewechat.com/wx13169e68a3e63e55/132/page-frame.html"